package buaa.leetcode.Math;

public class PalindromeNumber {
	public static boolean isPalindrome1(int x) {
		if(x < 0){return false;}
		long result = 0;
		int digitals = x;
		while(digitals != 0){
			int digital = digitals % 10;
			result = result * 10 + digital;
			digitals = digitals / 10;
		}
		if( (result >= Integer.MAX_VALUE) || (result != x) ){
			return false;
		}
        return true;
    }
	public static boolean isPalindrome2(int x) {
		if(x < 0){return false;}
		if(x < 10){return true;}
		int right = 1;
		int left = 1;
		while( (x / left) >= 10 ){
			left = left * 10;
		}
		while(left >= right){
			if( x/left % 10 != x/right % 10){
				return false;
			}
			left = left / 10;
			right = right * 10;
		}
        return true;
    }
	public static void main(String[] args){
		System.out.println(isPalindrome2(101));
	}
}
